<template>
  <!-- 添加或修改订单对话框 -->
  <el-dialog :close-on-click-modal="false" title="订单信息" :visible.sync="open" @close="cancel"
             width="700px" append-to-body>
    <el-form ref="form" :model="form" :rules="rules" label-width="110px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="订单号">
            <span>{{form.orderSn}}</span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="详细地址">
            <span>{{form.province}} {{form.city}} {{form.address}}</span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="联系电话">
            {{form.mobile}}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="收件人姓名">
            {{form.truename}}
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="物流类型" prop="logisticsType">
            <el-select v-model="form.logisticsType" placeholder="请选择物流类型">
              <el-option
                v-for="dict in logisticsTypeOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12" v-if="form.logisticsType == '顺丰快递'">
          <el-form-item label="物流号" prop="logisticsNumber">
            <el-input v-model="form.logisticsNumber" placeholder="请输入物流号"/>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">{{form.status == '2' ? '发 货':'确认编辑'}}</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import operationModule from '@/mixins/operation-module'
  import {
    addOrder,
    updateSendOut,
    updateLogisticsInfo
  } from '@/api/order/order'

  export default {
    name: 'add-or-update',
    mixins: [operationModule],
    data() {
      return {
        // 设置属性
        mixinOperationModuleOptions: {
          saveURL: addOrder, // 提交数据接口，api地址
          updateURL: updateSendOut // 提交数据接口，api地址
        },
        moduleName: 'Order',
        open: false,
        // 弹出层标题
        //表单操作类型
        formType: this.$formType.add,
        // 表单参数
        form: {},
        // 支付方式字典
        payTypeOptions: [],
        // 支付状态;0=待支付,1=已取消,2=已支付,3=待发货,4=已发货,5=已送达字典
        statusOptions: [],
        // 物流类型;SF=顺丰字典
        logisticsTypeOptions: [],
        // 表单校验
        rules: {}
      }
    },
    methods: {
      init(type) {
        this.reset()
        this.open = true
        if (type == this.$formType.add) {
        } else if (type == this.$formType.edit) {
        } else if (type == this.$formType.detail) {
        }
        this.formType = type
      },
      onStartSbmitForm() {
        if (this.form.status == '2') {
          this.mixinOperationModuleOptions.updateURL = updateSendOut
        } else if (this.form.status == '3') {
          this.mixinOperationModuleOptions.updateURL = updateLogisticsInfo
        } else {
          return false
        }
        return true
      },
      // 表单重置
      reset() {
        this.form = {
          id: undefined,
          uid: undefined,
          orderSn: undefined,
          transactionSn: undefined,
          payType: undefined,
          money: undefined,
          status: '0',
          createTime: undefined,
          payTime: undefined,
          sendOutTime: undefined,
          finishTime: undefined,
          remark: undefined,
          province: undefined,
          city: undefined,
          address: undefined,
          truename: undefined,
          mobile: undefined,
          logisticsNumber: undefined,
          logisticsType: undefined
        }

        this.resetForm('form')
      },
      cancel() {
        this.$emit('on-close')
        this.open = false
      }
    },
    created() {
      this.reset()
    }
  }
</script>
